package structure.concrete;

import structure.interfaces.INode;
import structure.interfaces.IOperatorNullary;

/**
 * this class represent the constant value in the chromosome
 * the class implements INode interface and therefore functions 
 * documentation can be found inside INode.java
 */
public class Constant extends IOperatorNullary {

	double value;
	
	/**
	 * set value to be random number between min to max
	 */
	public Constant() {
		value = Double.valueOf(utils.Utils.rand.nextInt(10))+1.0;
	}
	
	public Constant(double value) {
		this.value = value;
	}

	public void setValue(double value) {
		this.value = value;
	}
	
	@Override
	public double getValue(double x) {
		return value;
	}
	
	@Override
	public String getDescription() {
		if (value >= 0)
			return Double.toString(value);
		else
			return "(" + Double.toString(value) + ")";
	}

	public Constant clone() {
		return new Constant(value);
	}
	
	public INode clone(INode crossNode, INode newSubTree) {
		if (this == crossNode)
			return newSubTree.clone();
		else
			return new Constant(value);
	}

	
}
